<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>基本资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="/css/public.css" media="all">
  <style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
  </style>
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="editForm" id="editForm">

      <div class="layui-form-item">
        <input type="hidden" id="id" name="id" th:value="${session.CURRENT_ADMINISTRATOR.id}">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
          <label for="username"></label><input type="text" id="username" disabled name="username" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label required">昵称</label>
        <div class="layui-input-block">
          <label for="nickname"></label><input type="text" id="nickname" name="nickname" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label required">姓名</label>
        <div class="layui-input-block">
          <label for="name"></label><input type="text" id="name" name="name" placeholder="请输入姓名" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <label><input type="hidden" name="avatar" id="avatar"></label>
          <button type="button" class="layui-btn" id="ava"><i class="layui-icon"></i>修改头像</button>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
          <input type="radio" name="sex" value="男" title="男">
          <input type="radio" name="sex" value="女" title="女">
          <input type="radio" name="sex" value="保密" title="保密" checked>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
          <label>
            <input class="layui-input" type="text" name="tel" placeholder="请输入联系方式" autocomplete="off">
          </label>
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn" id="saveBtn">确认修改</button>
        </div>
      </div>

    </div>
  </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script>
  layui.use(['form', 'upload', 'miniTab'], function () {
    let form = layui.form,
        layer = layui.layer,
        miniTab = layui.miniTab,
        upload = layui.upload,
        $ = layui.jquery;

    $("#avatar").val('');

    $.get("/administrator/" + $("#id").val(), function(admin) {
        form.val("editForm", admin);
        form.render();
    });

    upload.render({
      elem: '#ava',
      url: '/administrator/avatar',
      accept: 'file', //普通文件
      done: function(res, index, upload){
        console.log(res.data.src);
        if(res.code === 0){
          $("#avatar").val(res.data.src);
        } // end if
      } //end done
    }); //end upload

    //监听提交
    $("#saveBtn").on("click", function () {
        let data = form.val("editForm");
        console.log(data);
        $.post("/administrator/edit", data, function () {
            miniTab.deleteCurrentByIframe();
            window.location.reload();
        });
    });

  });
</script>
</body>
</html>